import {
	AUTHENTICATION_KEY,
	token,
	domain
} from '@/stores/useApp'

let post = (url, params) => {
	let promise = new Promise((resolve, reject) => {
		uni.request({
			url: domain + url,
			method: "POST",
			data: {
				...params,
			},
			header: {
				[AUTHENTICATION_KEY]: token
			},
			success(res) {
				resolve(res.data);
			},
			fail(err) {				
				uni.showToast({
					"title": err.errMsg,
					duration: 10000
				});
				reject(err.errMsg);
			}
		})
	})
	
	return promise;
}

uni.post = post;

export default post;